<?php
ob_start();
if(!isset($_SESSION)){
session_start();
}
if(!isset($_SESSION["userName"])){
	header("location: login.php");
}
?>
<?php require_once ("../connection/connect.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>...:: eManazines ::...</title>
    <link rel="Stylesheet" href="css/style.css" type="text/css" />
    <link rel="Stylesheet" href="css/mystyle.css" type="text/css" />
     <script type="text/javascript" src="js/jquery.js"></script>
		
</head>
<body>
    <div class="wrapper">
    <?php include ("top.php");?>
        <div class="body">
          <div class="signup-right-wrapper">
                <h3>
                    Quản lý Nhóm
                </h3>
                <div class="signup-right">
                  <?php if(!isset($_GET['act'])){?>
                  <table width="760" border="1" align="center" cellpadding="1" cellspacing="0">
                    <tr>
                      <td width="26%">Group_id</td>
                      <td width="16%">Tên nhóm</td>
                      <td width="14%">Mô tả</td>
                      <td width="12%">Sửa</td>
                      <td width="10%">Xóa</td>
                    </tr>
                    <?php
					$rs = mysql_query("SELECT * FROM groups");
					while($r = mysql_fetch_array($rs)){
					?>
                    <tr>
                      <td><?php echo $r['group_id'];?></td>
                    
                      <td><?php echo $r['name'];?></td>
                      
                      <td><?php echo $r['info'];?></td>
                      <td><a href="manager_group.php?act=edit&amp;id=<?php echo $r['group_id'];?>">
                        <input type="submit" name="edit" id="edit" value="   Sửa   " />
                      </a> </td>
                      <td><a href="manager_goup.php?act=delete&amp;id=<?php echo $r['group_id'];?>">
                        <input type="submit" name="delete" id="delete" value="   Xóa   " />
                      </a></td>
                    </tr>
                    <?php }?>
                  </table>
                  <?php }?>
                  <?php if(isset($_GET['act'])&&($_GET['act']=='edit')){
			 $id = $_GET['id'];
			 ?>
                  <form name="fedit" id="fedit" action="" method="post">
                    <input type="hidden" name="id" id="id" value="<?php echo $id; ?>"/>
                    <table width="760" border="1" align="center" cellpadding="1" cellspacing="0">
                      <tr>
                        <td width="48%">Tên nhóm</td>
                        <td width="52%" colspan="2">Mô tả</td>
                      </tr>
                      <tr>
                        <td><input name="name" type="text" id="name" size="30"/>                        </td>
                        <td colspan="2"><input name="info" type="text" id="info" size="60"/>                        </td>
                      </tr>
                      <tr>
                        <td colspan="2" align="center"><input type="submit" name="edit_ok" value="Đồng ý Sửa"/></td>
                      </tr>
                    </table>
                  </form>
                  <?php
            if(isset($_POST['edit_ok'])){
            $id = $_POST['id'];
            $name = $_POST['name'];
			$info = $_POST['info'];	
			require_once("group.php");
			$group = new group();
			$group->edit($id,$name,$info);
			echo "Sửa thành công.";
            } 	
			?>
                  <?php }?>
                  <?php if(isset($_GET['act'])&&($_GET['act']=='delete')){
			$id = $_GET['id'];
			?>
                  <form action="" method="post">
                    <input type="hidden" name="id" id="id" value="<?php echo $id; ?>"/>
                    <table width="760" border="1" align="center" cellpadding="1" cellspacing="0">
                      <tr>
                        <td width="52%">Tên hiển thị</td>
                        <td width="48%">&nbsp;</td>
                      </tr>
                      <?php $res= mysql_fetch_array(mysql_query("SELECT * FROM groups WHERE group_id = $id"));?>
                      <tr>
                        <td><?php echo $res['name'];?></td>
                        <td><input name="delete_ok" type="submit" id="delete_ok" value="Đồng ý Xóa"/></td>
                      </tr>
                      <tr align="center">
                        <td height="48" colspan="2">&nbsp;</td>
                      </tr>
                    </table>
                  </form>
                  <?php
			if(isset($_POST['delete_ok'])){
			$id = $_POST['id'];
			require_once("group.php");
			$group = new group();
			$group->delete($id);
			echo "Xóa thành công.!";
			}
			?>
                  <?php }?>
                </div>
          </div>
            <div class="vide">
            </div>
        </div>
        <?php include("footer.php");?>
    </div>
</body>
</html>
